package com.kotlin.demo.泛型


/**
 * 泛型推断练习
 */

class KtBase108<Input>(val isR: Boolean, vararg objects: Input) {

    private val objectArray: Array<out Input> = objects

    fun getR1(): Array<out Input>? = objectArray.takeIf { isR }

    fun getR2(): Any = objectArray.takeIf { isR } ?: "jskdjsk"

    fun getR3(): Any? = objectArray.takeIf { isR } ?: "sdjkjf" ?: null

    fun getR4(index: Int): Input? = objectArray[index].takeIf { isR }

    fun getR5(index: Int): Any = objectArray[index].takeIf { isR } ?: "skdslfjs"

    fun getR6(index: Int): Any? = objectArray[index].takeIf { isR } ?: "sldjfsf" ?: null


}

fun main() {

    val p1: KtBase108<String?> = KtBase108(true, "aaa", "bbb", null)
    val p2: KtBase108<String> = KtBase108(true, "aaa", "bbb", "ccc")



}